﻿using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Revit;

namespace YArchitech.Plumbing.ExtendElementSet
{
	[Transaction(TransactionMode.Manual)]
	public class CommandExtend : HYExternalCommand
	{
		public override Result HYExecute(ref string TranName)
		{
			if (this.commandData == null)
			{
				throw new System.ArgumentNullException();
			}
			goto IL_0E;
			Result result;
            IL_0E:
			try
			{
					
				for (;;)
				{
					ExtendElementsHelper extendElementsHelper = new ExtendElementsHelper(base.UiDoc);
					if (extendElementsHelper.SelectAndGroupExtendingElements())
					{
						XYZ xyz = base.Sel.PickPoint("请选择拉伸（拖动）起始点：");
						if (xyz != null)
						{
							using (StretchElementsJig stretchElementsJig = new StretchElementsJig(base.UiDoc))
							{
								stretchElementsJig.StartPoint = xyz;
								stretchElementsJig.OutSideLines = extendElementsHelper.InterectElemsLine;
								stretchElementsJig.InSideLines = extendElementsHelper.InsideElemsLine;
								stretchElementsJig.GetHoriAndVertLines();
								base.Sel.PickPoint("请选择拉伸（拖动）终点：");
								XYZ movingVector = stretchElementsJig.MovingVector;
								extendElementsHelper.ExtendAndMovePickedElements(movingVector);
								stretchElementsJig.Dispose();
							}
						}
					}
				}
			}
			catch
			{
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			return result;
		}

		public override void FilterProcess()
		{
            base.FilterViewType.Add((ViewType)1);
            base.FilterViewType.Add((ViewType)2);
			base.FilterProcess();
		}
	}
}
